<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">

<head>
  <meta charset="UTF-8">
  <title>后台登录-ERP管理2.2</title>
  <th:block th:include="include::header" />
</head>
<body>
<div class="layui-fluid">
  <div class="layui-row">
    <form class="layui-form">
      <div class="layui-form-item">
        <div class="layui-input-inline">
          <input type="hidden" id="r_id" name="r_id" required="" lay-verify="r_id"
                 autocomplete="off" class="layui-input" th:value="${idRole.r_id}">
        </div>
      </div>
      <div class="layui-form-item">
        <label for="r_name" class="layui-form-label">
          <span class="x-red">*</span>角色名
        </label>
        <div class="layui-input-inline">
          <input type="text" id="r_name" name="r_name" required="" lay-verify="r_name"
                 autocomplete="off" class="layui-input" th:value="${idRole.r_name}">
        </div>
      </div>
      <div class="layui-form-item">
        <label for="r_state" class="layui-form-label">
          <span class="x-red">*</span>状态
        </label>
        <div class="layui-input-inline">
          <input type="text" id="r_state" name="r_state" required="" lay-verify="r_state"
                 autocomplete="off" class="layui-input" th:value="${idRole.r_state}">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label"><span class="x-red">*</span>权限</label>
        <div class="layui-input-block" th:each="item:${autoList}">
          <input type="checkbox" name="r_auto" lay-skin="primary" th:text="${item}" th:value="${item}" checked="checked">
        </div>
        <div class="layui-input-block" th:each="item1:${autoNewList}">
          <input type="checkbox" name="r_auto" lay-skin="primary" th:text="${item1}" th:value="${item1}">
        </div>
      </div>
      <div class="layui-form-item">
        <button  class="layui-btn" lay-filter="update" lay-submit="">
          修改
        </button>
      </div>
    </form>
  </div>
</div>
<script>layui.use(['form', 'layer'],
        function() {
          $ = layui.jquery;
          var form = layui.form,
                  layer = layui.layer;

          //监听提交
          form.on('submit(update)',
                  function(data) {
                    var arr = new Array();
                    $("input:checkbox[name='r_auto']:checked").each(function (){
                      arr.push($(this).val());
                    })
                    data.field.r_auto = arr.join(',');
                    console.log(data);
                    $.ajax({
                      url:"/role/updateAfter",
                      type:"POST",
                      data:data.field,
                      success(res){
                        if (res.success){
                          debugger
                          //发异步，把数据提交给php
                          layer.msg(res.msg,
                                  function() {
                                    //关闭当前frame
                                    xadmin.close();
                                    // 可以对父窗口进行刷新
                                    xadmin.father_reload();
                                  });
                        }else {
                          layer.msg(res.msg+":"+res.code)
                        }
                      }
                    })
                    return false;
                  });

        });</script>
<script>var _hmt = _hmt || []; (function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
  var s = document.getElementsByTagName("script")[0];
  s.parentNode.insertBefore(hm, s);
})();</script>
</body>

</html>
